<template>
  <div >
    <div style="text-align:left">
      患者信息：
      <el-tag>姓名:{{patient.realName}}</el-tag>
      <el-tag>病历号:{{patient.caseNumber}}</el-tag>
      <el-tag>年龄:{{patient.age}}</el-tag>
      <el-tag>性别:{{patient.gender}}</el-tag>
    </div>
    <el-divider></el-divider>
    <div style="font-size:20px;text-align:left">
      <i class="el-icon-document-checked">检查项目</i>
    </div>
    <el-divider></el-divider>

    <el-table :data="check_patient_table" style="width:80%;margin-top:5px" highlight-current-row @current-change="checkSelectionChange">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="techCode" label="检查编码"></el-table-column>
      <el-table-column prop="techName" label="检查名称"></el-table-column>
      <el-table-column prop="techFormat" label="检查规格"></el-table-column>
      <el-table-column prop="techPrice" label="单价"></el-table-column>
      <el-table-column prop="techType" label="费用分类"></el-table-column>
    </el-table>
    <div align="left">
      <el-tag>已选择的检查项目：{{ checkPatient.techName }}</el-tag>
    </div>

    <el-descriptions title="确认检查科室和检查医生" :column="2" border style="margin-top:20px;width:50%">
      <el-descriptions-item label="科室选择">
        <el-select v-model="deptmentId" placeholder="选择科室" @change="getDepartMentEmployee">
          <el-option v-for="item in check_dept" :key="item.id" :label="item.deptName" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="医生选择">
        <el-select v-model="employeeId" placeholder="选择医生">
          <el-option v-for="item in check_employee" :key="item.id" :label="item.realname" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
    </el-descriptions>
    <div style="text-align:left;margin-top:20px">
      <el-button type="primary" @click="addCheckPatient">开始检查</el-button>
      <el-button type="primary" @click="clearCheckPatient()">重置医生</el-button>
    </div>
  </div>
</template>
<script>
import {isNullMessage} from "../../util/util";
import qs from 'qs';
import {getSessionStorage} from "@/util/common";
import {ElMessage} from "element-plus";
export default{
  data(){
    return{
      checkPatient:{
        checkEmployeeId:'',
        id:'',
        techName:''
      },
      employeeId:'',//选择医生id
      check_employee:[],//检查科室医生列表
      deptmentId:'',//选择科室id
      check_dept:[],//检查科室列表
      check_patient_table:[],//患者的检查项目列表
      patient:{},//患者信息

    }    
  },
  methods:{

    //开始检查
    addCheckPatient:function (){
      if(this.checkPatient.techName=='')
      {
        ElMessage({
          type:"warning",
          message:'请选择检查的项目'
        })
        return
      }
      let url= 'http://localhost:8092/checkrequest/updatecheck'
      let value={
        id:this.checkPatient.rid,
        checkEmployeeId:this.employeeId
      }
      this.$axios.put(url,value).then(resp=>{
        ElMessage({
          type:'success',
          message:this.checkPatient.techName+":检查结束"
        })
        //更新状态
        this.updateState()
        this.getPatientMedicaltechnology()
      })
    },
    //更新状态
    updateState:function (){
      let ids=[];
      ids.push(this.checkPatient.rid)
      let url=`http://localhost:8092/checkrequest/updatestate/${ids}/3`
      this.$axios.get(url).then(resp=>{

      }).catch(error=>{
        console.log(error)
      })
    },
    //检查列表行发生改变时的事件对应的函数
    checkSelectionChange:function (row){
      //console.log(row);
      this.checkPatient=row
      console.log(this.checkPatient)
     // this.checkPatient.techName=row.techName
    },
    //得到当前患者的检查的项目
    getPatientMedicaltechnology:function ()
    {
      let url='http://localhost:8092/medicaltechnology/selectbyregiserid'
      let value={
        registerId:this.patient.id,
        checkState:'已缴费'
      }
      this.$axios.post(url,value).then(resp=>{
        this.check_patient_table=resp.data.result

      })
    },

    //得到科室下的医生
    getDepartMentEmployee:function ()
    {
      this.employeeId=''
      let url=`http://localhost:8092/register/selectbydepartmentid/${this.deptmentId}`
      this.$axios.get(url).then(resp=>{
      this.check_employee=resp.data.result
      })
    },
    //得到科室信息
    getRegisterDepart:function (){
      let deptType='检查'
      let url=`http://localhost:8092/register/getdepartment/${deptType}`
      this.$axios.get(url).then(resp=>{
        this.check_dept=resp.data.result
      }).catch(error=>{
        console.log(error)
      })
    },


  },
  mounted() {
    console.log(this.checkPatient)
    if(getSessionStorage("patient")==null)
    {
      ElMessage({
        type:"warning",
        message:"请选择患者！"
      })
      return
    }
    this.patient=getSessionStorage("patient");

    this.getPatientMedicaltechnology()

    this.getRegisterDepart()

  }
}
</script>
